<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\model\learn;
use app\api\service\User as UserService;
use app\common\model\learn\Chat as ChatModel;

/**
 *
 * Class Article
 * @package app\api\model
 */
class Chat extends ChatModel {

	public function getChat($followId) {
		$userId = UserService::getCurrentLoginUserId();
		$log = $this->with(['user.avatar'])->where('user_id', $userId)->where('follow_id', $followId)->find();
		if (!$log) {
			$data['user_id'] = $userId;
			$data['follow_id'] = $followId;
			$data['follow_user'] = $followId . '-' . $userId;
			$data['user_follow'] = $userId . '-' . $followId;

			$data['store_id'] = self::$storeId;
			$this->save($data);
			$log = $this->with(['user.avatar'])->where('user_id', $userId)->where('follow_id', $followId)->find();
			return $log;

		}

		return $log;
	}

}